import { Schema } from 'mongoose';
import { ISubTask } from '../types/ISubTask';

export const SubTaskSchema = new Schema<ISubTask>({
  subTaskId: { type: String, required: true },
  title: { type: String, required: true, maxlength: 200 },
  description: { type: String, maxlength: 500 },
  status: {
    type: String,
    enum: ['pending', 'in_progress', 'completed', 'cancelled'],
    default: 'pending'
  },
  priority: {
    type: String,
    enum: ['low', 'medium', 'high', 'urgent'],
    default: 'medium'
  },
  assignedTo: { type: String },
  estimatedDuration: { type: Number, min: 0 },
  actualDuration: { type: Number, min: 0 },
  dependencies: [{ type: String }], // 其他子任务的ID
  progress: { type: Number, min: 0, max: 100, default: 0 },
  dueDate: { type: Date },
  completedAt: { type: Date }
}, {
  timestamps: true,
  _id: false // 作为嵌入文档，不需要单独的_id
});
